home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks95 / IsNative.sit / Is Native / AboutAnimation.c < prev    next >
Text File  |  1995-06-24  |  4KB  |  212 lines

  1. //
  2. // File:    AboutAnimation.c
  3. // Project:    IsNative.π
  4. // Author:    Glenn L. Austin
  5. //            Symantec Corporation
  6. //
  7. #include <QDOffscreen.h>
  8. #include <Traps.h>
  9. #include "IsNative.h"
  10.  
  11. typedef pascal Boolean (*GNEPP)(short, EventRecord*);
  12.  
  13. extern WindowPtr    aboutWindow;
  14. static Str255        aboutStr = "\p%PNormal=68K, %IItalic%I=PPC, %B%CBold%P=fat •• Is Native? ©1995, Glenn L. Austin, All rights reserved worldwide.     ";
  15. Rect                aboutR = {42, 0, 54, 377};
  16. Rect                srcR, targR;
  17. GWorldPtr            aboutGW = nil;
  18. static GNEPP        oldGetNextEvent;
  19. static unsigned long    lastTick;
  20.  
  21. static pascal Boolean MyGetNextEvent(short mask, EventRecord* evt)
  22. {
  23.     long            oldA4 = SetA4World();
  24.     Rect            r;
  25.     unsigned long    ticksBetweenUpdate = 4;
  26.     Boolean            retVal = (*oldGetNextEvent)(mask, evt);
  27.     short            adder = -1;
  28.     GrafPtr            oldPort;
  29.     
  30.     if (aboutWindow && aboutGW)
  31.     {
  32.         if (evt->modifiers & alphaLock)
  33.             ticksBetweenUpdate = 0xFFFFFFFF;
  34.         else
  35.         {
  36.             if (evt->modifiers & cmdKey)
  37.                 ticksBetweenUpdate >>= 2;        // cmd key = 4x as fast
  38.             else if (evt->modifiers & optionKey)
  39.                 ticksBetweenUpdate >>= 1;        // option key = 2x as fast
  40.         }
  41.                 
  42.         if (TickCount() - lastTick >= ticksBetweenUpdate)
  43.         {
  44.             GetPort(&oldPort);
  45.             SetPort(aboutWindow);
  46.             
  47.             LockPixels(GetGWorldPixMap(aboutGW));
  48.             r = targR;
  49.             r.left += adder;
  50.             r.right += adder;
  51.             // first time, draw in new location, then unoffset the rectangle and erase the old
  52.             CopyBits(&((GrafPtr)aboutGW)->portBits, &aboutWindow->portBits, &srcR, &r,
  53.                         srcCopy, nil);
  54.                 
  55.             if (r.right < aboutR.right)
  56.             {
  57.                 OffsetRect(&r, r.right - r.left, 0);
  58.                 CopyBits(&((GrafPtr)aboutGW)->portBits, &aboutWindow->portBits, &srcR, &r,
  59.                         srcCopy, nil);
  60.             }
  61.             UnlockPixels(GetGWorldPixMap(aboutGW));
  62.             
  63.             targR.left += adder;
  64.             targR.right += adder;
  65.             
  66.             if (targR.right < 0)
  67.                 OffsetRect(&targR, targR.right - targR.left, 0);
  68.             
  69.             SetPort(oldPort);
  70.             
  71.             lastTick = TickCount();
  72.         }
  73.     }
  74.     
  75.     RestoreA4World(oldA4);
  76.     
  77.     return(retVal);
  78. }
  79.  
  80. void StartAnimation(void)
  81. {
  82.     GrafPtr        oldPort;
  83.     OSErr        err;
  84.     CGrafPtr    oldGW;
  85.     GDHandle    oldGD;
  86.     
  87.     if (!aboutGW)
  88.     {
  89.         short    wid = 0;
  90.         short    nextChar;
  91.         Style    currStyle = 0;
  92.         short    txFont;
  93.         short    txSize;
  94.         Style    txFace;
  95.         
  96.         GetPort(&oldPort);
  97.         SetPort(aboutWindow);
  98.         
  99.         txFont = aboutWindow->txFont;
  100.         txSize = aboutWindow->txSize;
  101.         txFace = aboutWindow->txFace;
  102.         
  103.         TextFont(geneva);
  104.         TextSize(9);
  105.         TextFace(currStyle);
  106.         
  107.         for (nextChar = 1; nextChar <= aboutStr[0]; ++nextChar)
  108.         {
  109.             if (aboutStr[nextChar] == '%')
  110.             {
  111.                 switch (aboutStr[++nextChar])
  112.                 {
  113.                     case 'P':
  114.                         currStyle = 0;
  115.                         break;
  116.                     case 'B':
  117.                         currStyle ^= bold;
  118.                         break;
  119.                     case 'I':
  120.                         currStyle ^= italic;
  121.                         break;
  122.                     case 'C':
  123.                         currStyle ^= condense;
  124.                         break;
  125.                 }
  126.                 TextFace(currStyle);
  127.             }
  128.             else
  129.                 wid += CharWidth(aboutStr[nextChar]);
  130.         }
  131.         
  132.         aboutWindow->txFont = txFont;
  133.         aboutWindow->txSize = txSize;
  134.         aboutWindow->txFace = txFace;
  135.         
  136.         SetPort(oldPort);
  137.  
  138.         // now, create a GWorld that is wid pixels wide and 13 pixels tall
  139.         GetGWorld(&oldGW, &oldGD);
  140.         srcR.left = 0;
  141.         srcR.top = 0;
  142.         srcR.bottom = 12;
  143.         srcR.right = wid;
  144.         err = NewGWorld(&aboutGW, 1, &srcR, nil, nil, useTempMem);
  145.         if (!err && aboutGW)
  146.         {
  147.             LockPixels(GetGWorldPixMap(aboutGW));
  148.             SetGWorld(aboutGW, nil);
  149.             EraseRect(&srcR);
  150.             
  151.             currStyle = 0;
  152.             TextFont(geneva);
  153.             TextSize(9);
  154.             TextFace(currStyle);
  155.     
  156.             // draw the string into the GWorld
  157.             MoveTo(0, 9);
  158.             for (nextChar = 1; nextChar <= aboutStr[0]; ++nextChar)
  159.             {
  160.                 if (aboutStr[nextChar] == '%')
  161.                 {
  162.                     switch (aboutStr[++nextChar])
  163.                     {
  164.                         case 'P':
  165.                             currStyle = 0;
  166.                             break;
  167.                         case 'B':
  168.                             currStyle ^= bold;
  169.                             break;
  170.                         case 'I':
  171.                             currStyle ^= italic;
  172.                             break;
  173.                         case 'C':
  174.                             currStyle ^= condense;
  175.                             break;
  176.                     }
  177.                     TextFace(currStyle);
  178.                 }
  179.                 else
  180.                     DrawChar(aboutStr[nextChar]);
  181.             }
  182.             
  183.             SetGWorld(oldGW, oldGD);
  184.             UnlockPixels(GetGWorldPixMap(aboutGW));
  185.         }
  186.     }
  187.  
  188.     targR = srcR;
  189.     OffsetRect(&targR, aboutR.right, aboutR.top);
  190.     
  191.     lastTick = 0;
  192.     
  193.     if (!oldGetNextEvent)
  194.     {
  195.         oldGetNextEvent = (void*) GetToolTrapAddress(_GetNextEvent);
  196.         SetToolTrapAddress((void*) MyGetNextEvent, _GetNextEvent);
  197.     }
  198. }
  199.  
  200. void StopAnimation(void)
  201. {
  202.     GrafPtr        oldPort;
  203.     
  204.     if (oldGetNextEvent)
  205.         SetToolTrapAddress((void*) oldGetNextEvent, _GetNextEvent);
  206.     oldGetNextEvent = nil;
  207.     
  208.     //if (aboutGW)
  209.     //    DisposeGWorld(aboutGW);
  210.     //aboutGW = nil;
  211. }
  212.